﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using CQIE.TES.IDAL;
using CQIE.TES.IService;
using CQIE.TES.Model;
using Newtonsoft.Json.Linq;

namespace CQIE.TES.Service
{
    public class TeacherService:ITeacherService
    {

        private readonly ITeacherDAL _dal;


        //注入ITeacherDAL对象
        public TeacherService(ITeacherDAL dal)
        {
            this._dal = dal;
        }


        public void test()
        {
            _dal.testdel();
        }

        public void testdel()
        {
            _dal.testdel();
        }
        
        public bool FreezeUser(int id)
        {
            return _dal.FreezeUser(id);
        }

        public Teacher FindByID(int id)
        {
            return _dal.FindById(id);
        }

        public List<Teacher> GetTeachersPage(int pageNum, int pageSize, string search,out int count)
        {
            return _dal.GetTeachersPage(pageNum-1, pageSize, search,out count);
        }

        public void ResetPassWord(int id)
        {
            _dal.ResetPassWord(id);
        }

        public List<Teacher> GetAllTeachers()
        {
            return _dal.GetAllTeachers();
        }

        

        public void InsertTeacher([FromBody] JObject data)
        {
            string teacherName = data["teacherName"].ToString();
            DateTime age = (DateTime)data["age"];
            string workNumber = data["workNumber"].ToString();
            string phone = data["phone"].ToString();
            int sex = Convert.ToInt32(data["sex"]);
            int role =Convert.ToInt32(data["role"]);
            string info = data["info"].ToString();
            _dal.InsertTeacher(sex,teacherName, age, workNumber, phone, role, info);
        }


        public void updata([FromBody] JObject data)
        {
            string teacherName = data["teacherName"].ToString();
            //DateTime age = (DateTime)data["age"];
            string workNumber = data["workNumber"].ToString();
            string phone = data["phone"].ToString();
            int sex = Convert.ToInt32(data["sex"]);
            int role = Convert.ToInt32(data["role"]);
            string info = data["info"].ToString();
            int id = data.Value<int>("id");
            _dal.Updata(id, sex, teacherName, workNumber, phone, role, info);
        }

        public List<Teacher> GetDepartMentTeachers(int uid)
        {
            return _dal.GetDepartMentTeachers(uid);
        }

        public Teacher Login(string username, string password)
        {
            return _dal.Login(username, password);
        }

        public List<Teacher> SearchByName(string name)
        {
            return _dal.SearchByName(name);
        }
    }
}
